package com.chinacache.maint.workorder.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.chinacache.maint.commons.orm.hibernate.Page;
import com.chinacache.maint.commons.orm.hibernate.SimpleHibernateDao;
import com.chinacache.maint.workorder.entity.WorkOrderStep;

@Transactional
public class WorkOrderStepManager {
	private SimpleHibernateDao<WorkOrderStep, Integer> workOrderStepDao;

	@Required
	public void setSessionFactory(SessionFactory sessionFactory) {
		workOrderStepDao = new SimpleHibernateDao<WorkOrderStep, Integer>(
				sessionFactory, WorkOrderStep.class);
	}

	@Transactional(readOnly = true)
	public WorkOrderStep getWorkOrderStep(Integer id) {
		return workOrderStepDao.findById(id);
	}

	@Transactional(readOnly = true)
	public Page<WorkOrderStep> getAllWorkOrderStep(Page<WorkOrderStep> page) {
		return workOrderStepDao.findAll(page);
	}

	public void saveWorkOrderStep(WorkOrderStep workOrderStep) {
		workOrderStepDao.save(workOrderStep);
	}

	public void deleteWorkOrderStep(Integer id) {
		WorkOrderStep workOrderStep = workOrderStepDao.findById(id);
		workOrderStepDao.delete(workOrderStep);
	}

	public void updateWorkOrderStep(WorkOrderStep workOrderStep) {
		workOrderStepDao.update(workOrderStep);
	}

	@Transactional(readOnly = true)
	public List<WorkOrderStep> getAllWorkOrderStep() {
		return workOrderStepDao.findAll();
	}

	@Transactional(readOnly = true)
	public List<WorkOrderStep> getAllWorkOrderStepByOrder(Integer order) {
		String queryString = "select wos from WorkOrderStep wos where wos.order<"
				+ order;
		return workOrderStepDao.find(queryString);
	}
}
